Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
How to decrypt AES SubtleCrypto [window.subtle.crypto] at CryptoJS

I'm attempting to migrate from Browser-only window.subtle.crypto to CryptoJS so it is universally available across all platforms using Expo.

Essentially: window.subtle.encrypt({name: AES-GCM}) -> CryptoJS.AES.decrypt

For the existing data encrypted, CryptoJS should be able to decrypt it utilizing the AES generated key from window.subtle.generateKey, so the method for window.subtle.encrypt cannot be changed and it's being done as described below

I want to decrypt the window.subtle.encrypt encrypted at CryptoJS's CryptoJS.AES.decrypt

so for this, I've written this test code:

const text = "This is an encrypted message";

const generateKey = async () => {
    const key = await window.crypto.subtle.generateKey({ name: "AES-GCM", length: 128 }, true, ["encrypt", "decrypt"]);
    const key_exported = await window.crypto.subtle.exportKey("jwk", key);
    return key_exported.k;
}

const printCurrent = async () => {
        let kkey = await generateKey();
        await window.crypto.subtle.importKey(
            "jwk",
            {
                k: kkey,
                alg: "A128GCM",
                ext: true,
                key_ops: ["encrypt", "decrypt"],
                kty: "oct",
            },
            { name: "AES-GCM", length: 128 },
            false,
            ["encrypt", "decrypt"]
        ).then(function(key){
            window.crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12) }, key, new TextEncoder().encode(JSON.stringify(text))).then( function(encryptedObject){
            const cryptojs = CryptoJS.AES.decrypt(encryptedObject,key,{iv: new Uint8Array(12));
            console.log("cryptojs: ", cryptojs.toString(CryptoJS.enc.Utf8));
            });
        } );
    }
    printCurrent();

I've seen that CryptoJS accepts only WordArray, and the output of the encrypted object ['encryptedObject'] from subtle crypto is ArrayBuffer [46 size], I've tried converting ArrayBuffer to WordArray via CryptoJS.lib.WordArray.create(encryptedObject) but still no luck.

Any help or guidance is appreciated, thanks so much!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda